Option Explicit

' startCell -- 写入 sheet 的默认单元格 = B2
Private Const START_CELL_DEFAULT_VALUE As String = "B2"
' newSheetName -- 新 sheet 名称的默认值
Private Const NEW_SHEET_NAME_DEFAULT_VALUE As String = "mdTable"

Public Sub main()
    Dim wb As Workbook
    Set wb = ActiveWorkbook

    Dim form As VBComponent
    Set form = wb.VBProject.VBComponents.Item("MdTableToSheetForm")

    ' ==================================================
    ' 1. 设置 form 的属性
    ' ==================================================
    With form
        .Properties("Height") = 300
        .Properties("Width") = 386
        .Properties("Caption") = "MdTableToSheet"
    End With

    Dim ctrs As Controls
    Set ctrs = form.Designer.Controls

    ' ==================================================
    ' 2. 第一行
    ' ==================================================
    ' 1. 设置: startCell -- 标识写入 sheet 时的起始单元格
    '    标题
    UtilsControl.createLabel ctrs, "startCellLabel", _
        18, 56, 18, 18, caption:="startCell", fontSize:=11

    '    输入框
    UtilsControl.createTextBox ctrs, "startCellInput", _
        24, 48, 78, 12, _
        fontSize:=12, text:=START_CELL_DEFAULT_VALUE, value:=START_CELL_DEFAULT_VALUE, tabIndex:=1

    ' 2. needEmptyRow -- 是否需要表格中的空行
    UtilsControl.createCheckBox ctrs, "needEmptyRowCheckBox", _
        24, 82, 132, 12, _
        caption:="needEmptyRow", value:=True, tabIndex:=2

    ' 3. skipSecondSplitRowCheckbox -- 是否需要忽略表头和内容的分割行
    UtilsControl.createCheckBox ctrs, "skipSecondSplitRowCheckbox", _
        24, 105, 216, 12, _
        caption:="skipSecondSplitRow", value:=True, tabIndex:=3

    ' ==================================================
    ' 3. 第二行
    ' ==================================================
    ' 1. 设置: markdown Table -- 标识写入 markdown table 的字符串
    '    标题
    UtilsControl.createLabel ctrs, "markdownTableLabel", _
        18, 90, 18, 42, caption:="markdown Table", fontSize:=11

    ' 2. 设置: newSheetName -- 标识新 sheet 的名称
    '    标题
    UtilsControl.createLabel ctrs, "newSheetNameLabel", _
        18, 78, 132, 42, caption:="newSheetName", fontSize:=11

    '    输入框
    UtilsControl.createTextBox ctrs, "newSheetNameInput", _
        24, 138, 216, 36, _
        fontSize:=12, text:=NEW_SHEET_NAME_DEFAULT_VALUE, value:=NEW_SHEET_NAME_DEFAULT_VALUE, tabIndex:=4

    ' ==================================================
    ' 4. 第三行
    ' ==================================================
    '    markdown Table 输入框
    UtilsControl.createTextBox ctrs, "mdTableInput", _
        132, 336, 18, 66, _
        fontSize:=12, multiLine:=True, tabIndex:=5

    ' ==================================================
    ' 5. 第四行
    ' ==================================================
    ' 1. 按钮: 转换并写出到活动 sheet
    UtilsControl.createButton ctrs, "createToActiveSheetBtn", _
        30, 96, 30, 222, _
        caption:="createToActiveSheet", fontSize:=9, tabIndex:=6

    ' 2. 按钮: 创建一个新sheet，并写出转换后的数据
    UtilsControl.createButton ctrs, "createToNewSheetBtn", _
        30, 90, 204, 222, _
        caption:="createToNewSheet", fontSize:=9, tabIndex:=7
End Sub
